package algorithm;

/**
 * 112. 路径总和
 * @author Panbo Guo
 * @date 2021/7/20
 */
public class T00112 {

    public static void main(String[] args) {
        Integer[] arr = new Integer[]{1,2};
        System.out.println(new Solution().hasPathSum(TreeUtils.buildTree(arr), 1));
    }

    static class Solution {
        public boolean hasPathSum(TreeNode root, int targetSum) {
            if (root == null)
                return false;
            targetSum -= root.val;
            if (targetSum == 0 && root.left == null && root.right == null)
                return true;
            return hasPathSum(root.left, targetSum) || hasPathSum(root.right, targetSum);
        }
    }
}
